<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OpenMesh: Using IO::Options</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="logo_align.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="rwth_vci_rgb.jpg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">OpenMesh
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('a04344.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Using IO::Options </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This example shows:</p>
<ul>
<li>How to control the behaviour of <code>Mesh::IO::read_mesh()</code>,</li>
<li>How to control the behaviour of <code>Mesh::IO::write_mesh()</code>.</li>
</ul>
<p>The class <code><a class="el" href="a02029.html" title="Set options for reader/writer modules. ">OpenMesh::IO::Options</a></code> can be used when reading/writing a mesh. It controls the behaviour of the reader/writer modules by means of enabled/disabled bits in a bitset. The class provides an interface for enabling, disabling and verifying the bits in the set. We distinguish between</p>
<ol type="1">
<li>mode bits - control binary reading/writing<ul>
<li>Options::Binary</li>
<li>Options::MSB</li>
<li>Options::LSB</li>
<li>Options::Swap (MSB|LSB)</li>
</ul>
</li>
<li>property bits - controls which standard properties to read/write<ul>
<li>Options::VertexNormal</li>
<li>Options::VertexTexCoord</li>
<li>Options::VertexColor</li>
<li>Options::FaceNormal</li>
<li>Options::FaceColor</li>
<li>Options::FaceTexCoord</li>
<li>Options::ColorAlpha</li>
<li>Options::ColorFloat</li>
<li>Options::Custom</li>
</ul>
</li>
</ol>
<p>These bits have different effects when reading or writing. The file format itself is selected by the extension of the filename.</p>
<p>Please take into account, each mesh has to <b>request</b> the standard property <b>before loading</b> with the corresponding option. For instance, if you enable Options::VertexNormal, your mesh has to request vertex normals. Otherwise, they will not be written into the mesh.</p>
<dl class="section note"><dt>Note</dt><dd>Face Tex Coords will not be saved as a property per face, but as a property per halfedge. Therefore, you have to request the "halfedge_texcoords2D" property</dd></dl>
<p>The OBJ-reader can also read information about the textures in the *.mtl file, if available. These texture information (includes texturename and index) will be saved in the property of type: </p><div class="fragment"><div class="line"><a class="code" href="a02569.html">OpenMesh::MPropHandleT&lt; std::map&lt; int, std::string &gt;</a> &gt; </div></div><!-- fragment --><p> with the name: </p><div class="fragment"><div class="line"><span class="stringliteral">&quot;TextureMapping&quot;</span> </div></div><!-- fragment --><p> This property will be automatically created, if textures were found. There is no other option you have to define for reading texture information beside of the request of the property.<br />
Additionally, the OBJ loader writes the texture index per face, if the property "face_texture_index" is requested. The texture index is the same index as the index written in the texture mapping. So, it is possible to get the name of the texture from a face via its texture index over the texture mapping property to the texture name. But remember, you have to request the face texture index property first before loading the mesh.</p>
<p>Below in the table you can see what options are suported by which reader/writer (it is possible that the data format can support more). ASCII is not a real option and will be selected, if binary was not defined.</p>
<a class="anchor" id=""></a>
<table class="doxtable">
<caption><em>Reader/Writer Feature Support List</em></caption>
<tr>
<th>Format/Option</th><td>ASCII</td><td>Binary</td><td>MSB</td><td>LSB</td><td>Swap</td><td>VertexNormal</td><td>VertexColor</td><td>VertexTexCoord</td><td>EdgeColor</td><td>FaceNormal</td><td>FaceColor</td><td>FaceTexCoord</td><td>ColorAlpha</td><td>ColorFloat</td><td>Custom </td></tr>
<tr>
<th>OBJ</th><td>x</td><td></td><td></td><td></td><td></td><td>x</td><td>x *)</td><td>x</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td></td><td></td></tr>
<tr>
<th>OFF</th><td>x</td><td>x</td><td></td><td>x</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td></td><td>x</td><td></td><td>x</td><td>x</td><td></td></tr>
<tr>
<th>PLY</th><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td>x</td><td>x</td><td>x</td><td></td><td></td><td>x</td><td></td><td>x</td><td>x</td><td>x **) </td></tr>
<tr>
<th>OM</th><td></td><td>x</td><td>x</td><td>x</td><td>x</td><td>x</td><td>x</td><td>x</td><td></td><td>x</td><td>x</td><td></td><td></td><td></td><td>x (<a class="el" href="a04345.html">Using custom properties (old style)</a> ) </td></tr>
<tr>
<th>STL</th><td>x</td><td>x</td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td><td>x</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr>
<th>VTK ***)</th><td>x</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
<p>*) can <em>read</em> the non-standard extension vertex colors (floats only): </p><ul>
<li>defined with vc (e.g. used by meshlab) </li>
<li>colors encoded in a vertex line (v followed by 6 values)</li>
</ul>
<p>**) only vertex and face properties with fundamental types. Take into account, that you don't have to request these custom properties before loading.</p>
<p>***) no reader exists</p>
<p>The program does not more than providing a command line based interface to select the option bits for reading/writing and to request mesh properties. Hence illegal combinations are possible and will result in a failure of the program. (The input file won't be damaged in this case, but be careful where you put the ouput file!)</p>
<h5>Reading meshes</h5>
<p>When reading a file the mode bits are used to give the reader an advice or hint. Depending on the format we can help the reader to interpret the data correctly. First of all we can tell it that the file contains binary data.</p>
 <div class="fragment"><div class="line">        ropt += IO::Options::Binary; </div></div><!-- fragment --></p>
<p>Further on we can ask the reader two swap the byte-order.</p>
<p><div class="fragment"><div class="line">        ropt += IO::Options::Swap; </div></div><!-- fragment --></p>
<p>(Both can be done via the command line with the options -b and -s, respectively.)</p>
<p>By default the geometry and the topology is restored from the file. The file might contain more, especially it could provide normals or texture coordinates. We can examine the property bits after reading to find out what else is available:</p>
 <div class="fragment"><div class="line">                ropt.check(IO::Options::VertexNormal) </div></div><!-- fragment --></p>
<p>If a property bit is set it does not mean, that it has been restored as well. The property must have been requested prior reading the file. (The demo program offers the command line option <code>-Xv</code>[nct] and <code>-Xf</code>[nc] to request vertex and face properties.)</p>
<h5>Writing meshes</h5>
<p>When writing the mesh the mode bits apparently control whether to use the binary variant and the desired byte-ordering. For example, if we choose binary mode and want to swap the byte order, we set</p>
<p><div class="fragment"><div class="line">        wopt += IO::Options::Binary; </div><div class="line">        wopt += IO::Options::Swap; </div></div><!-- fragment --></p>
<p>If the format does not specify the byte order the system byte order is used. If the format does not support binary storage, the mode bits are ignored.</p>
<p>If the format supports storing additional information, which are conform with the standard properties, we can use the property bits to tell the writer what we would like to have stored. If we would like to store the vertex normals we simply set</p>
<p><div class="fragment"><div class="line">              wopt += IO::Options::VertexNormal; </div></div><!-- fragment --></p>
<p>Finally we can write the data to the file</p>
 <div class="fragment"><div class="line">  <span class="keywordflow">if</span> ( !IO::write_mesh( mesh, argv[optind+1], wopt ) )</div></div><!-- fragment --></p>
<p>The method returns false on error, which might have three different reasons:</p>
<ol type="1">
<li>the option is not supported by the choosen format</li>
<li>a selected standard property is not available</li>
<li>a 'system' error like<ul>
<li>could not open the file due to access rights</li>
<li>disk space exhausted during write</li>
<li>...</li>
</ul>
</li>
</ol>
<p>The complete source looks like this:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iterator&gt;</span></div><div class="line"><span class="comment">// -------------------- OpenMesh</span></div><div class="line"><span class="preprocessor">#include &lt;OpenMesh/Core/IO/MeshIO.hh&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;OpenMesh/Tools/Utils/getopt.h&gt;</span></div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="a01233.html">OpenMesh</a>;</div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keyword">typedef</span> <a class="code" href="a02377.html">TriMesh_ArrayKernelT&lt;&gt;</a>  MyMesh;</div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define CHKROPT( Option ) \</span></div><div class="line"><span class="preprocessor">  std::cout &lt;&lt; &quot;  provides &quot; &lt;&lt; #Option \</span></div><div class="line"><span class="preprocessor">            &lt;&lt; (ropt.check(IO::Options:: Option)?&quot;: yes\n&quot;:&quot;: no\n&quot;)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define CHKWOPT( Option ) \</span></div><div class="line"><span class="preprocessor">  std::cout &lt;&lt; &quot;  write &quot; &lt;&lt; #Option \</span></div><div class="line"><span class="preprocessor">            &lt;&lt; (wopt.check(IO::Options:: Option)?&quot;: yes\n&quot;:&quot;: no\n&quot;)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define MESHOPT( msg, tf ) \</span></div><div class="line"><span class="preprocessor">  std::cout &lt;&lt; &quot;  &quot; &lt;&lt; msg &lt;&lt; &quot;: &quot; &lt;&lt; ((tf)?&quot;yes\n&quot;:&quot;no\n&quot;)</span></div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> parse_commandline( <span class="keywordtype">int</span> _argc, <span class="keywordtype">char</span> **_argv, MyMesh&amp; _mesh,</div><div class="line">                        <a class="code" href="a02029.html">IO::Options</a> &amp;ropt, <a class="code" href="a02029.html">IO::Options</a> &amp;wopt );</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> usage_and_exit(<span class="keywordtype">int</span> xcode);</div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  MyMesh  mesh;</div><div class="line">  <a class="code" href="a02029.html">IO::Options</a> ropt, wopt;</div><div class="line"></div><div class="line">  <span class="comment">// -------------------- evaluate commandline</span></div><div class="line"></div><div class="line">  parse_commandline( argc, argv, mesh, ropt, wopt );</div><div class="line"></div><div class="line">  <span class="comment">// -------------------- read mesh</span></div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( ! <a class="code" href="a01236.html#ac417960ec28ffdd7e7003a2b1ebb2d1c">IO::read_mesh</a>(mesh,argv[optind], ropt))</div><div class="line">  {</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;Error loading mesh from file &quot;</span> &lt;&lt; argv[optind] &lt;&lt; std::endl;</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// -------------------- show options</span></div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;File &quot;</span> &lt;&lt; argv[optind] &lt;&lt; std::endl;</div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  is binary: &quot;</span> </div><div class="line">            &lt;&lt; (ropt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5cb7f45e7ba928e0a23e4a676d10fa8a">IO::Options::Binary</a>) ? <span class="stringliteral">&quot; yes\n&quot;</span> : <span class="stringliteral">&quot; no\n&quot;</span>);</div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  byte order: &quot;</span>;</div><div class="line">  <span class="keywordflow">if</span> (ropt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a35dfdd7a0af4b3c83fbdec77a6428ba3">IO::Options::Swap</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;swapped\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ropt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ac53f41d3b8306a764e7382372d56b7ec">IO::Options::LSB</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;little endian\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ropt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5976f96b11378c06f15f99bef6cc5f19">IO::Options::MSB</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;big endian\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;don&#39;t care\n&quot;</span>;</div><div class="line">  </div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  provides VertexNormal&quot;</span></div><div class="line">            &lt;&lt; ( <span class="comment">// strange layout for doxygen</span></div><div class="line">                ropt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ad989c6d671050e12953b648c4c72dded">IO::Options::VertexNormal</a>) </div><div class="line">                ? <span class="stringliteral">&quot;: yes\n&quot;</span>:<span class="stringliteral">&quot;: no\n&quot;</span>);</div><div class="line">  CHKROPT( VertexColor    );</div><div class="line">  CHKROPT( VertexTexCoord );</div><div class="line">  CHKROPT( FaceNormal     );</div><div class="line">  CHKROPT( FaceColor      );</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// -------------------- mesh stats</span></div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;# Vertices: &quot;</span> &lt;&lt; mesh.n_vertices() &lt;&lt; std::endl;</div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;# Edges   : &quot;</span> &lt;&lt; mesh.n_faces() &lt;&lt; std::endl;</div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;# Faces   : &quot;</span> &lt;&lt; mesh.n_faces() &lt;&lt; std::endl;</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// -------------------- show write options</span></div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;Selected write options:\n&quot;</span>;</div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  use binary: &quot;</span> </div><div class="line">            &lt;&lt; (wopt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5cb7f45e7ba928e0a23e4a676d10fa8a">IO::Options::Binary</a>) ? <span class="stringliteral">&quot; yes\n&quot;</span> : <span class="stringliteral">&quot; no\n&quot;</span>);</div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  byte order: &quot;</span>;</div><div class="line">  <span class="keywordflow">if</span> (wopt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a35dfdd7a0af4b3c83fbdec77a6428ba3">IO::Options::Swap</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;swapped\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (wopt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ac53f41d3b8306a764e7382372d56b7ec">IO::Options::LSB</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;little endian\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (wopt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5976f96b11378c06f15f99bef6cc5f19">IO::Options::MSB</a>))</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;big endian\n&quot;</span>;</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;don&#39;t care\n&quot;</span>;</div><div class="line">  </div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;  write VertexNormal&quot;</span></div><div class="line">            &lt;&lt; (wopt.check(<a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ad989c6d671050e12953b648c4c72dded">IO::Options::VertexNormal</a>) ? <span class="stringliteral">&quot;: yes\n&quot;</span>:<span class="stringliteral">&quot;: no\n&quot;</span>);</div><div class="line">  CHKWOPT( VertexColor    );</div><div class="line">  CHKWOPT( VertexTexCoord );</div><div class="line">  CHKWOPT( FaceNormal     );</div><div class="line">  CHKWOPT( FaceColor      );</div><div class="line"></div><div class="line">  <span class="comment">// -------------------- show mesh capabilities</span></div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;Mesh supports\n&quot;</span>;</div><div class="line">  MESHOPT(<span class="stringliteral">&quot;vertex normals&quot;</span>, mesh.has_vertex_normals());</div><div class="line">  MESHOPT(<span class="stringliteral">&quot;vertex colors&quot;</span>, mesh.has_vertex_colors());</div><div class="line">  MESHOPT(<span class="stringliteral">&quot;texcoords&quot;</span>, mesh.has_vertex_texcoords2D());</div><div class="line">  MESHOPT(<span class="stringliteral">&quot;face normals&quot;</span>, mesh.has_face_normals());</div><div class="line">  MESHOPT(<span class="stringliteral">&quot;face colors&quot;</span>, mesh.has_face_colors());</div><div class="line"></div><div class="line">  <span class="comment">// -------------------- write mesh</span></div><div class="line"></div><div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;Write mesh to &quot;</span> &lt;&lt; argv[optind+1] &lt;&lt; <span class="stringliteral">&quot;..&quot;</span>;</div><div class="line">  <span class="keywordflow">if</span> ( !<a class="code" href="a01236.html#a18286a792ebf896872f5e26182fc5c7b">IO::write_mesh</a>( mesh, argv[optind+1], wopt ) )</div><div class="line">  {</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;Error&quot;</span> &lt;&lt; std::endl;</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;Possible reasons:\n&quot;</span>;</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;1. Chosen format cannot handle an option!\n&quot;</span>;</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;2. Mesh does not provide necessary information!\n&quot;</span>;</div><div class="line">    std::cerr &lt;&lt; <span class="stringliteral">&quot;3. Or simply cannot open file for writing!\n&quot;</span>;</div><div class="line">    <span class="keywordflow">return</span> 1;</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Ok.\n&quot;</span>;</div><div class="line"></div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> parse_commandline( <span class="keywordtype">int</span> _argc, <span class="keywordtype">char</span> **_argv, MyMesh&amp; _mesh,</div><div class="line">                        <a class="code" href="a02029.html">IO::Options</a> &amp;ropt, <a class="code" href="a02029.html">IO::Options</a> &amp;wopt )</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> c;</div><div class="line">  <span class="keywordflow">while</span> ((c=getopt(_argc, _argv, <span class="stringliteral">&quot;bhsBF:LMSV:X:&quot;</span>))!=-1)</div><div class="line">  {</div><div class="line">    <span class="keywordflow">switch</span>(c) </div><div class="line">    {</div><div class="line">      <span class="comment">// -------------------- read options</span></div><div class="line"></div><div class="line">      <span class="comment">// force binary input</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;b&#39;</span>: </div><div class="line">        ropt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5cb7f45e7ba928e0a23e4a676d10fa8a">IO::Options::Binary</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// force swapping the byte order, when reading a binary file</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;s&#39;</span>: </div><div class="line">        ropt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a35dfdd7a0af4b3c83fbdec77a6428ba3">IO::Options::Swap</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// -------------------- write options</span></div><div class="line"></div><div class="line">      <span class="comment">// Write binary variant of format if possible</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;B&#39;</span>: </div><div class="line">        wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5cb7f45e7ba928e0a23e4a676d10fa8a">IO::Options::Binary</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// </span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;F&#39;</span>:</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; optarg[i]; ++i)</div><div class="line">          <span class="keywordflow">switch</span>(optarg[i]) {</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;n&#39;</span> : wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a20ffc1477fa85d5ba3623817f71d1b39">IO::Options::FaceNormal</a>; <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span> : wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a3e0b1cda32fe42bde7ac3dc96f977a46">IO::Options::FaceColor</a>; <span class="keywordflow">break</span>;</div><div class="line">          }</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Use little endian when writing binary data</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;L&#39;</span>: </div><div class="line">        wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ac53f41d3b8306a764e7382372d56b7ec">IO::Options::LSB</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Use big endian when writing binary data</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;M&#39;</span>: </div><div class="line">        wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a5976f96b11378c06f15f99bef6cc5f19">IO::Options::MSB</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Swap byte order when writing binary data</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;S&#39;</span>: </div><div class="line">        wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21a35dfdd7a0af4b3c83fbdec77a6428ba3">IO::Options::Swap</a>; </div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">//</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;V&#39;</span>:</div><div class="line">      {</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; optarg[i]; ++i)</div><div class="line">          <span class="keywordflow">switch</span>(optarg[i]) {</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;n&#39;</span> : <span class="comment">// dont&#39;t change layout!!</span></div><div class="line">              wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ad989c6d671050e12953b648c4c72dded">IO::Options::VertexNormal</a>; </div><div class="line">              <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;t&#39;</span> : wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21ae9e664738c4c48ac057770fb08a723f0">IO::Options::VertexTexCoord</a>; <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span> : wopt += <a class="code" href="a02029.html#a9f4f797b08c045b611eaa6f8d149da21af7b6bb87f12fdfe5c9a8f8e1ce9325c7">IO::Options::VertexColor</a>; <span class="keywordflow">break</span>;</div><div class="line">          }</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line"></div><div class="line">      <span class="comment">// -------------------- request mesh&#39; standard properties</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;X&#39;</span>:</div><div class="line">      {        </div><div class="line">        <span class="keywordtype">char</span> entity=<span class="charliteral">&#39;\0&#39;</span>;</div><div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; optarg[i]; ++i)</div><div class="line">          <span class="keywordflow">switch</span>(optarg[i]) {</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>: </div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;f&#39;</span>: entity = optarg[i]; <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;n&#39;</span>:</div><div class="line">              <span class="keywordflow">switch</span>(entity) {</div><div class="line">                <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>: _mesh.request_vertex_normals(); <span class="keywordflow">break</span>;</div><div class="line">                <span class="keywordflow">case</span> <span class="charliteral">&#39;f&#39;</span>: _mesh.request_face_normals(); <span class="keywordflow">break</span>;</div><div class="line">              }</div><div class="line">              <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span>:</div><div class="line">              <span class="keywordflow">switch</span>(entity) {</div><div class="line">                <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>: _mesh.request_vertex_colors(); <span class="keywordflow">break</span>;</div><div class="line">                <span class="keywordflow">case</span> <span class="charliteral">&#39;f&#39;</span>: _mesh.request_face_colors(); <span class="keywordflow">break</span>;</div><div class="line">              }</div><div class="line">              <span class="keywordflow">break</span>;</div><div class="line">            <span class="keywordflow">case</span> <span class="charliteral">&#39;t&#39;</span>:</div><div class="line">              <span class="keywordflow">switch</span>(entity) {</div><div class="line">                <span class="keywordflow">case</span> <span class="charliteral">&#39;v&#39;</span>: _mesh.request_vertex_texcoords2D(); <span class="keywordflow">break</span>;</div><div class="line">              }</div><div class="line">              <span class="keywordflow">break</span>;</div><div class="line">          }</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">      </div><div class="line">      <span class="comment">// -------------------- help</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;h&#39;</span>:</div><div class="line">        usage_and_exit(0);</div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        usage_and_exit(1);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( _argc-optind != 2)</div><div class="line">    usage_and_exit(1);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// ----------------------------------------------------------------------------</span></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> usage_and_exit(<span class="keywordtype">int</span> xcode)</div><div class="line">{</div><div class="line">  std::ostream &amp;os = xcode ? std::cerr : std::cout;</div><div class="line"></div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;Usage: io_options [Options] &lt;input&gt; &lt;output&gt;\n&quot;</span> </div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;  Read and write a mesh, using OpenMesh::IO::Options\n&quot;</span></div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;Options:\n&quot;</span></div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;a) read options\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -b\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tAssume input file is a binary file\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -s\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tSwap byte order when reading a binary file!\n&quot;</span></div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;b) write options\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -B\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tWrite binary data\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -S\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tSwap byte order, when writing binary data\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -M/-L\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tUse MSB/LSB byte ordering, when writing binary data\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -V{n|t|c}\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tWrite vertex normals, texcoords, and/or colors\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -F{n|c}\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tWrite face normals, and/or colors\n&quot;</span></div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  os &lt;&lt; <span class="stringliteral">&quot;c) Mesh properties\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -Xv{n|c|t}\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tRequest vertex property normals|colors|texcoords\n&quot;</span></div><div class="line">     &lt;&lt; std::endl</div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;  -Xf{n|c}\n&quot;</span></div><div class="line">     &lt;&lt; <span class="stringliteral">&quot;\tRequest face property normals|colors\n&quot;</span></div><div class="line">     &lt;&lt; std::endl;</div><div class="line">  exit(xcode);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// end of file</span></div><div class="line"><span class="comment">// ============================================================================</span></div></div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<hr>
<address>
<small>
<a href="http://www.rwth-graphics.de" style="text-decoration:none;">
</a>
Project <b>OpenMesh</b>, 
&copy;&nbsp; Computer Graphics Group, RWTH Aachen.
Documentation generated using 
<a class="el" href="http://www.doxygen.org/index.html">
<b>doxygen</b>
</a>.
</small>
</address>
</body>
</html>
